#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int bank_balance = 10;
void* deposit_func (void *arg){
    int inc = *((int *)arg);
    int i;

    int temp = bank_balance;
    for(i=0;i<inc;i++){
        temp++;
    }
    bank_balance = temp;

    return NULL;
}
int main(int argc, char *argv[]){
    /* TODO: complete main function */
    pthread_t trans1, trans2;
    if(argc<2)
        exit(1);
    int deposit = atoi(argv[1]);
    int expected = 10 + deposit * 2;
    pthread_create(&trans1, NULL, deposit_func, &deposit);
    pthread_create(&trans2, NULL, deposit_func, &deposit);

    pthread_join(trans1, NULL);
    pthread_join(trans2, NULL);

    if(bank_balance==expected)
        printf("%d\n", bank_balance);
    //expected is rarely calculated correctly when trans1 and trans2 run
    //concurrently. It's even rare when the arg is larger.

    return 0;
}
